<template>
    <div>
        <el-input @input="inputChange(item)" v-model="value"></el-input>
        子里：{{ value }}
    </div>
</template>
<script>
    export default {
        //组件名
        name: "InputItem",
        //获取父值
        props: ["item", "valueF"],
        data() {
            return {
                //父传子需要重新定义
                value: this.valueF
            };
        },
        methods: {
            inputChange(obj) {
                let that = this;
                //console.log(that[item],123);
                if (obj.isNum) {
                    let reg = /^[0-9]+$/;
                    let isInt = reg.test(that.value);
                    if (!isInt) {
                        that.$nextTick(function() {
                            that.value = "";
                            //子传父
                            that.$emit("changeEnd", this.value);
                        });
                        that.$message.warning("只能输入数字");
                    }
                }
                //子传父
                that.$emit("changeEnd", this.value);
            }
        }
    };
</script>
